{include file="./headStart.tpl"}
<script type="text/javascript">
var i = 0;
$(document).ready(function(){
 $(".add").click(function(){
   $("#one").clone(true).appendTo("#mainDiv").find('input[type="text"]').val('');
  });
});
function calAmount(theRate)
{
	var row = $(theRate).parents('#tableRow');
	var quantity = parseFloat(row.find(".quantity").val());
	var rate = parseFloat(row.find(".unitRate").val());
	row.find(".unitAmount").val(quantity * rate);
}
function deleteRow(theObj) 
{
  $(theObj).parent().parent().remove();
}
//change total Start :: 
function totAmountChange()
{
	var totGrossWeight = 0;
  
  $('.unitAmount').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totGrossWeight += Number(price);
  });
  
  $('.textAmount').each(function(i)
  {
    price = $(this).val().replace("$","");
    if (!isNaN(price)) totGrossWeight += Number(price);
  });
  $('#totAmount').val(totGrossWeight.toFixed(3));
}
//change total End ::
function submitFunction()
{
	if($('.unitAmount:last').val() != '')
	{
		$('#proformaSubmit').val(1);
		$("form").submit();
	}
	else
	{
		$('.unitRate:first').focus();
		return false;
	}
}
</script>
{include file="./headEnd.tpl"}
<form name="frmProforma" action="{$smarty.server.PHP_SELF}" id="formId" method="POST">
<input type="hidden" name="masterDeliveryId" value="{$deliveryDetailArray[0][0].masterDeliveryId}" />
<table align="center">
<tr>
  <td class="table5" align="center" colspan="10"><B>Create Proforma</td>
</tr>
<tr>
  <td class="table5" align="center" colspan="10"><B>Proforma Sr. No. : {$srNo}</td>
</tr>
<tr>
  <td class="table1" align="center"><B>Customer</td>
	<td class="table1" align="center"><B>Challan No</td>
	<td class="table1" align="center"><B>Challan Type</td>
  <td class="table1" align="left">SubCategory</td>
  <td class="table1" align="center">Item</td>
  <td class="table1" align="center">Quantity</td>
  <td class="table1" align="center">Unit Rate</td>
  <td class="table1" align="center">Amount</td>
</tr>
{section name="sec" loop=$deliveryChallanArray}
	  {section name="sec1" loop=$deliveryDetailArray[sec]}
	    <tr id="tableRow">
	    	<input type="hidden" name="deliveryChallanMasterId[]" value="{$deliveryDetailArray[sec][sec1].deliveryChallanMasterId}" />
	      {if $deliveryDetailArray[sec][sec1].display == 1}
		      <td class="table3" align="left">{$deliveryDetailArray[sec][sec1].companyName}</td>
		      {else}
		      <td class="table3" align="center">&nbsp;</td>
	      {/if}
		      <td class="table3" align="center">{$deliveryDetailArray[sec][sec1].srNo}</td>
		      <td class="table3" align="right">{$deliveryDetailArray[sec][sec1].challanType}</td>
	        <input type="hidden" name="deliveryChallanDetailId[]" id="deliveryChallanDetailId" value="{$deliveryDetailArray[sec][sec1].deliveryChallanDetailId}" />
	        <input type="hidden" name="itemId[{$deliveryDetailArray[sec][sec1].deliveryChallanDetailId}]" id="itemId" value="{$deliveryDetailArray[sec][sec1].itemId}" />
	        <input type="hidden" name="quantity[{$deliveryDetailArray[sec][sec1].deliveryChallanDetailId}]" id="quantity" value="{$deliveryDetailArray[sec][sec1].quantity}" />
		      <td class="table3">{$deliveryDetailArray[sec][sec1].subCategoryName}</td>
		      <td class="table3" NOWRAP>{$deliveryDetailArray[sec][sec1].itemName}</td>
		      <td class="table3" align="right">{$deliveryDetailArray[sec][sec1].quantity}<input type="hidden" class="quantity" value="{$deliveryDetailArray[sec][sec1].quantity}" /></td>
		      <td class="table3" align="right"><input type="text" class="unitRate" value="0" name="unitRate[{$deliveryDetailArray[sec][sec1].deliveryChallanDetailId}]" id="unitRate" onblur="calAmount(this);" /></td>
		      <td class="table3" align="right"><input type="text" class="unitAmount" name="unitAmount[{$deliveryDetailArray[sec][sec1].deliveryChallanDetailId}]" onblur="totAmountChange();" /></td>
	    </tr>
	 {/section}
  {/section}
</tr>
</table>
<table align="center">
<tr>
  <td class="table1" align="center"><B>Text</td>
	<td class="table1" align="center"><B>Amount</td>
	<td class="table1" align="center"><B>&nbsp;</td>
	<td class="table1" align="center"><B>&nbsp;</td>
</tr>
<tbody id="mainDiv">
	<tr id="one">
		<td class="table2"><input type="text" name="textName[]"/></td>
		<td class="table2"><input type="text" name="textAmount[]" id="textAmount" class="textAmount" onblur="totAmountChange();" /></td>
		<td class="table2"><input type="button" name="add"  class="add" value="Add" /></td>
    <td class="table2"><input type="button" value="Delete" name="deleteBtn"  class="delete" onclick="deleteRow(this)"/></td>
	</tr>
</table>
<table align="center">
	<tr>
		<td class="table1" colspan="3">Total Amount</td>
		<td class="table1"><input type="text" name="totAmount" id="totAmount"></td>
	</tr>
	<tr>
    <td class="table1" align="center" colspan="4"><B>Special Notes</td>
  </tr>
  <tr>
    <td class="table2" align="center" colspan="4"><textarea name="notes"/></textarea></td>
  </tr>
</table>
<center>
	<input type="hidden" name="proformaSubmit" id="proformaSubmit" value="0" />
	<input type="button" value="Submit" onclick="submitFunction();" /></center>
</form>